package com.ciwong.epaper.modules.me.widget;

import android.content.Context;
import android.graphics.Rect;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.ciwong.epaper.util.DisplayUtils;

public class SpaceItemDecoration extends RecyclerView.ItemDecoration {
    private int space;  //位移间距
    private int left;  //间距
    private int right;  //位移间距
    private Context mContext;

    public SpaceItemDecoration(Context context, int space, int left, int right) {
        this.space = space;
        this.left = left;
        this.right = right;
        this.mContext = context;
    }

    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
        if (parent.getChildAdapterPosition(view) % 2 == 0) {
            outRect.left = DisplayUtils.dip2px(mContext, left);
            outRect.right = DisplayUtils.dip2px(mContext, space / 2);
        } else {
            outRect.left = DisplayUtils.dip2px(mContext, space / 2);
            outRect.right = DisplayUtils.dip2px(mContext, right);
        }
    }
}